package com.xiaomi.eco.dal.query;


import java.io.Serializable;

public class ApiResult implements Serializable {

    private static final long serialVersionUID = 1199872738772265178L;

    /**
     * @Description: 状态码,200:成功
     */
    private int code=200;
    /**
     * @Description: 提示信息
     */
    private String message="操作成功";



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() { return message; }

    public void setMessage(String message) { this.message = message; }


    public ApiResult(){

        this.message="success";
    }

    public ApiResult(String message){

        this.message=message;
    }

    public ApiResult(int code, String message){
        this.code=code;
        this.message=message;
    }

    public void setCodeMessage(ApiErrorCode errorCode,String message){
        this.code=errorCode.getCode();
        this.message=message;
    }

    public void setCodeMessage(ApiErrorCode errorCode){
        this.code=errorCode.getCode();
        this.message=errorCode.getMessage();
    }



    /**
     * @Description: 成功返回
     * @Author: ZSH
     * @Date: 2018/12/25 12:57
     * @param
     * @return ApiResult
     */
    public static ApiResult addSuccess(){
        ApiResult apiResult = new ApiResult(ApiErrorCode.success.getCode(),ApiErrorCode.success.getMessage());
        return apiResult;
    }

    /**
     * @Description: 成功返回
     * @Author: ZSH
     * @Date: 2018/12/25 12:57
     * @param message
     * @return ApiResult
     */
    public static ApiResult addSuccess(String message){

        ApiResult apiResult = new ApiResult(ApiErrorCode.success.getCode(),message);
        return apiResult;
    }


    /**
     * @Description: 生成失败结果集，填充状态码和错误信息
     * @Author: ZSH
     * @Date: 2018/12/25 12:57
     * @param message
     * @return ApiResult
     */
    public static  ApiResult addFail(ApiErrorCode apiErrorCode,String message){

        ApiResult apiResult = new ApiResult (apiErrorCode.getCode(),message);
        return  apiResult;
    }

    /**
     * @Description: 生成失败结果集，填充状态码和错误信息
     * @Author: ZSH
     * @Date: 2018/12/25 12:57
     * @return ApiResult
     */
    public static ApiResult addFail(){
        return  addFail(ApiErrorCode.server_exception.getMessage());
    }

    /**
     * @Description: 生成失败结果集，填充状态码和错误信息
     * @Author: ZSH
     * @Date: 2018/12/25 12:57
     * @return ApiResult
     */
    public static ApiResult addFail(String message){

        return addFail(ApiErrorCode.server_exception,message);

    }

    /**
     * @Description: 生成失败结果集，填充状态码和错误信息
     * @Author: ZSH
     * @Date: 2018/12/25 12:57
     * @return ApiResult
     */
    public static  ApiResult addFail(ApiErrorCode apiErrorCode){

        ApiResult apiResult = addFail (apiErrorCode,apiErrorCode.getMessage());
        return  apiResult;
    }
}
